/*
 * @Author: Eli.Chen
 * @Date: 2025-05-07 12:20:37
 * @LastEditors: Eli.Chen
 * @LastEditTime: 2025-05-07 14:33:58
 * @Description:
 */
import React, { useState } from 'react';
import AssistantIcon from './AssistantIcon';
import AssistantDialog from './AssistantDialog';

export default function SmartAssistant() {
    const [visible, setVisible] = useState(true);
    const [dialogVisible, setDialogVisible] = useState(false);
    const [position, setPosition] = useState({
        x: window.innerWidth - 60,
        y: window.innerHeight - 60,
    });

    const handleDrag = (e) => {
        if (e.clientX === 0 || e.clientY === 0) return;
        setPosition({ x: e.clientX - 30, y: e.clientY - 30 });
    };

    const handleDragEnd = () => {
        if (position.x < window.innerWidth * 0.1) {
            setVisible(false);
        }
    };

    return (
        visible && (
            <>
                <AssistantIcon
                    iconStyle={{ width: 36, height: 36 }}
                    onDrag={handleDrag}
                    onDragEnd={handleDragEnd}
                    position={position}
                    onClick={() => setDialogVisible(true)}
                />
                <AssistantDialog visible={dialogVisible} onClose={() => setDialogVisible(false)} position={position} />
            </>
        )
    );
}
